using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BuildRoadWalk : MonoBehaviour
{
    public GameObject TrojanPrefab;
    public string objectName = "Door";
    public GameObject prefab;
    public GameObject parent;
    public GameObject targetObject;
    public float speed = 3.0f;
    float x,z,p;
    void Start()
    {
        x = transform.position.x;//暂时无用

        z = transform.position.z;
        p = z;
        //创建最开始的Road
        //Instantiate(prefab,gameObject.transform.position,Quaternion.identity,parent.transform);
    }
    void Update()
    {
        if(transform.position.z - p > 20){
            targetObject.AddComponent<NavMeshSu>();


            //创建数据出现的门户
            GameObject newObject = new GameObject(objectName);
            //更改位置为当前道路生成点
            newObject.transform.position = transform.position;
            //添加门户生成数据的逻辑
            SpawnScripts spawnScripts = newObject.AddComponent<SpawnScripts>();
            // 动态设置 SpawnScripts 中的 public 变量
            spawnScripts.prefab = TrojanPrefab;

            Destroy(gameObject);
            
        }
        transform.Translate(0,0,speed * Time.deltaTime);

        
        if(transform.position.z - z >= 1){
            z = transform.position.z;
            Instantiate(prefab,gameObject.transform.position,Quaternion.identity,parent.transform);
        }

    }
}
